<template>
  <div>
<!--    面包屑导航-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
<!--    卡片式图区域-->
    <el-card>
<!--      搜索区域-->
      <!-- 搜索与添加区域 -->
      <el-row :gutter="12">
        <el-col :span="4">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrderList">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
<!--      订单表格区域-->
      <el-table
        :data="orderList"
        style="width: 100%"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        border
        stripe>
        <el-table-column
         type="index">
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="180">
        </el-table-column>
        <el-table-column
          prop="order_pay"
          label="是否付款">
          <el-tag v-if="order_pay" type="success">已付款</el-tag>
          <el-tag v-else type="danger">未付款</el-tag>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货">
        </el-table-column>
        <el-table-column
          prop="dateFormat(create_time)"
          label="下单时间">
          <template slot-scope="scope">{{scope.row.create_time | dateFormat}}</template>
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="showEditForm(scope.row)"></el-button>
          <el-button type="success" size="mini" icon="el-icon-location"  @click="showLocation(scope.row.order_id)"></el-button>
          </template>
        </el-table-column>
      </el-table>
<!--      分页区域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
<!--    显示物流信息的对话框-->
    <el-dialog
      title="物流进度"
      :visible.sync="showLocationVisible"
      width="50%">
      <el-timeline :reverse="false">
        <el-timeline-item
          v-for="(item, i) in locationInfo"
          :key="i"
          :timestamp="item.ftime">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>

  </div>
</template>
<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      //  订单绑定的数据
      orderList: [],
      //  数据总数
      total: 0,
      //  是否显示物流对话框
      showLocationVisible: false,
      //  物流数据
      locationInfo: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    //  获取订单数据
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单数据失败！')
      }
      console.log(res.data)
      this.total = res.data.total
      this.orderList = res.data.goods
      this.$message.success('获取订单参数成功！')
    },
    //  监听页大小改变
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    //  监听当前页改变
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrderList()
    },
    //  展示编辑的表单对话框
    showEditForm() {},
    //  查看物流信息
    async showLocation(id) {
      this.showLocationVisible = true
      console.log(id)
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流数据失败！')
      }
      console.log(res.data)
      this.locationInfo = res.data
      this.$message.success('获取取物流数据成功！')
    }
  }
}
</script>
<style lang="less" scoped></style>
